package com.atguigu.mapreduce.writableComparbale;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, FlowBean,Text> {
    private FlowBean outK = new FlowBean();
    private Text outV = new Text();
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, FlowBean, Text>.Context context) throws IOException, InterruptedException {

        //获取一行
        String line = value.toString();

        // 切割
        String[] split = line.split("\t");

        outV.set(split[1]);
        outK.setUpFlow(Long.parseLong(split[split.length - 3]));
        outK.setDownFlow(Long.parseLong(split[split.length - 2]));
        outK.setSumFlow();

        //写出
        context.write(outK,outV);
    }
}
